﻿import pygame, sys, math, random

from Wall import Wall
from knives import Knife
from Player import Player
from Enemy import Enemy

clock = pygame.time.Clock()


width = 1200
height = 900
size = width, height

screen = pygame.display.set_mode(size)

bgImage = pygame.image.load("rsc/background/bgwosp.png")
bgRect = bgImage.get_rect()

bgColor = r,g,b = 0,0,0

player = Player([13,13], [56,72], [width/2,height/2])
                    
esize = random.randint(25, 50)

weapons = []

enemies = [Enemy(["rsc/enemie/enemy1.png", "enemy2.png", "enemy3.png"],
              [5, 5], 
              [75, 75], 
              [random.randint(110, width-110), random.randint(110, height-110)])]
              
walls = [Wall(15*1.875,190*1.875,55*1.875,8*1.875),
         Wall(140*1.875,195*1.875,68*1.875,8*1.875),
         Wall(215*1.875,225*1.875,90*1.875,8*1.875),
         Wall(399*1.875,225*1.875,245*1.875,8*1.875),
         Wall(0,0,640*1.875,8*1.875),
         Wall(0,0,132*1.875,35*1.875),
         Wall(0,0,10*1.875,480*1.875),
         Wall(634*1.875,5*1.875,11*1.875,480*1.875),
         Wall(0,470*1.875,640*1.875,10*1.875),
         Wall(200*1.875,79*1.875,10*1.875,480*1.875),
         Wall(450*1.875,360*1.875,10*1.875,480*1.875),
         Wall(450*1.875,228*1.875,10*1.875,65*1.875),
         Wall(25*1.875,233*1.875,70*1.875,45*1.875),
         Wall(224*1.875,385*1.875,80*1.875,55*1.875),
         Wall(10*1.875,400*1.875,50*1.875,8*1.875),
         Wall(105*1.875,400*1.875,25*1.875,8*1.875),
         Wall(170*1.875,400*1.875,25*1.875,8*1.875),
         Wall(110*1.875,400*1.875,10*1.875,70*1.875),
         ]
# wall3 = [Wall * 1.875 for Wall in(walls)] 
             
start = False
while True:
    while not start:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    start = True
        
        screen.blit(bgImage, bgRect)
        pygame.display.flip()
        clock.tick(60)             

    bgImage = pygame.image.load("rsc/background/bgwosp.png")
    
    level = 1
    
    while start:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                    player.direction("right")
                if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                    player.direction("left")
                if event.key == pygame.K_w or event.key == pygame.K_UP:
                    player.direction("up")
                if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                    player.direction("down")
                if event.key == pygame.K_SPACE:
                    weapons += [Knife(player.rect.center, player.angle)]  
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                    player.direction("stop right")
                if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                    player.direction("stop left")
                if event.key == pygame.K_w or event.key == pygame.K_UP:
                    player.direction("stop up")
                if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                    player.direction("stop down")
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    weapons += [Knife(player.rect.center, player.angle)]          
        
        for enemy in enemies:
            enemy.collideWall(width, height)
        player.collideWall(width, height)
        
    # for player in Player:
        # if self.rect.right > enemy.rect.left and self.rect.left < enemy.rect.right:
            # if self.rect.bottom > enemy.rect.top and self.rect.top < enemy.rect.bottom:
                # if self.rect.center[0] > enemy.rect.center[0]:
                    # self.living = True 
                # if self.rect.center[0] < enemy.rect.center[0]:
                    # self.living = True 
                # if self.rect.center[1] > enemy.rect.center[1]:
                    # self.living = True
                # if self.rect.center[1] < enemy.rect.center[1]:
                    # self.living = True 

                    
        for weapon in weapons:
            weapon.update()
            for wall in walls:
                weapon.collidewallsegment(wall)
            for enemy in enemies:
                enemy.collideKnife(weapon)
                if not enemy.living:
                    enemies.remove(enemy)
                   
        player.update()
        for enemy in enemies:
            enemy.update()
        
        for wall in walls:
            player.colidewallsegment(wall)
            for enemey in enemies:
                enemey.colidewallsegment(wall)        
        
        for enemy in enemies:
            enemy.collideWall(width, height)
            enemy.moveEnemy(player.rect.center)
        
        if len(enemies) > 1:
            for first in range(len(enemies)-1):
                for second in range(first+1,len(enemiess)):
                    enemies[first].collideEnemy(enemies[second])
        
        
               
        for weapon in weapons:
            print ">>>>>>>>>>>>>>>>>>>>>>>"
            print weapon.living
            if not weapon.living:
                weapons.remove(weapon)
                  
        print "::::::::::::::::::::::::::::::::", len(enemies)
        for enemy in enemies:
            
            if not enemy.living:
                enemies.remove(enemy)
                
                
    # level = 2    
            
    # for enemy in enemies:
        # if enemy.living = False
        
        
        
        
        
              
        
        for wall in walls:
            screen.blit(wall.image, wall.rect)
        screen.blit(bgImage, bgRect)
        screen.blit(player.image, player.rect)
        for enemey in enemies:
            screen.blit(enemy.image, enemy.rect)
        for weapon in weapons:
            screen.blit(weapon.image, weapon.rect)
        print  player.rect.center
        pygame.display.flip()
        clock.tick(60)
        
        
        
        
        
        
        
        
        
        
        
        
 
        # USLESS, SERIOUSLY THIS IS ALL CRAP RIGHT NOW, ALL OF IT!
     



     
  # enemy1.living = True and enemy2.living = True
                    # if enemy1.living = False and if enemy2.living = False
                        # enemy3.living = True and enemy4.living = True
                        # if enemy3.living = False and if enemy4.living = False
                                
                                    # if enemy.living = False
                                        # if enemy.living = False
                                            # if enemy.living = False
                    
      # from rocket-blaster-o-5000-o
    # bgImage = pygame.image.load("kf\rsc\background\end screen")    
    # while start and not player.living:
        # for event in pygame.event.get():
            # if event.type == pygame.QUIT:
                # sys.exit()
            # if event.type == pygame.KEYDOWN:
                # if event.key == pygame.K_q or event.key == pygame.K_ESCAPE:
                    # sys.exit()
 

     
            
        # for weapon in weapons:
            # weapon.update()
            # for wall in walls:
                # weapon.collidewallsegment(wall)
            # for enemy in enemies:
                # enemy.collideKnife(enemy)
                # enemies.remove(enemy)
                   
        # player.update()
        # for enemy in enemies:
            # enemy.update()
        
        # for wall in walls:
            # player.colidewallsegment(wall3)
            # for enemey in enemies:
                # enemey.colidewallsegment(wall3)        
        
        # for enemy in enemies:
            # enemy.collideWall(width, height)
            # enemy.moveEnemy(player.rect.center)
        
        # if len(enemies) > 1:
            # for first in range(len(enemies)-1):
                # for second in range(first+1,len(enemiess)):
                    # enemies[first].collideEnemy(enemies[second])
        
        
               
        # for weapon in weapons:
            # print ">>>>>>>>>>>>>>>>>>>>>>>"
            # print weapon.living
            # if not weapon.living:
                # weapons.remove(weapon)
                  
        # print "::::::::::::::::::::::::::::::::", len(enemies)
        # for enemy in enemies:
            
            # if not enemy.living:
                # enemies.remove(enemy)
                
                
        
                    
        
        # for wall in wall3:
            # screen.blit(wall.image, wall.rect)
        # screen.blit(bgImage, bgRect)
        # screen.blit(player.image, player.rect)
        # for enemey in enemies:
            # screen.blit(enemy.image, enemy.rect)
        # for weapon in weapons:
            # screen.blit(weapon.image, weapon.rect)
        # print  player.rect.center
        # pygame.display.flip()
        # clock.tick(60)